/**
 * 
 */
package com.ez.supervise.service.impl;

import java.util.List;

import com.ez.supervise.core.Page;
import com.ez.supervise.dao.OrgDao;
import com.ez.supervise.model.sys.Org;
import com.ez.supervise.service.OrgService;

/**
 * @author searph.wang
 * @email searph.wang@gmail.com
 * @Created at 2009-7-22
 * 
 */
public class OrgServiceImpl implements OrgService {
    private OrgDao orgDao;

    // public int update(Org org) {
    // return sqlMapClientTemplate.update("sys.updateOrg", org);
    // }

    public void setOrgDao(OrgDao orgDao) {
	this.orgDao = orgDao;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#delete(java.lang.Long)
     */
    public void delete(Long id) {
	orgDao.delete(id);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#insert(java.lang.Object)
     */
    public void insert(Object entity) {
	Org org = (Org)entity;
	if(org.getOrgOrder() != null && org.getOrgOrder() > 0){
	    orgDao.updateOrderByOrg(org.getOrgOrder());
	} else {
	   int orgOrder = orgDao.maxOrderByOrg();
	   org.setOrgOrder(orgOrder + 1);
	}
	orgDao.insert(org);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#update(java.lang.Object)
     */
    public void update(Object entity) {
	orgDao.update(entity);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#get(java.lang.Long)
     */
    public Object get(Long id) {
	return (Org) orgDao.get(id);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.ez.supervise.service.OrgService#findByPage(com.ez.supervise.core.
     * Page)
     */
    public Page findByPage(Page page) {
	page.setTotalProperty(orgDao.findByCount(page));
	page.setRoot(orgDao.findByPage(page));
	return page;

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.OrgService#findAll()
     */
    public List findAll() {
	return orgDao.findAll();
    }

    public List findOrgByType(String orgType) {
	return orgDao.findOrgByType(orgType);
    }
}
